package mh.demo.other.ognl;

import mh.demo.other.PrintUtils;
import ognl.Ognl;
import ognl.OgnlException;

public class OgnlDemo {

    public static void main(String[] args) throws OgnlException {
        OgnlDemo demo = new OgnlDemo();
        demo.firstDemo();
    }

    public void firstDemo() throws OgnlException {
        Student stu = new Student("Lucy", 18);
        PrintUtils.println("stu.name = " + Ognl.getValue("name", stu));
        PrintUtils.println("stu.age > 10 is " + Ognl.getValue("age > 10", stu));
    }

    private static class Student {
        private final String name;
        private final Integer age;

        public Student(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public Integer getAge() {
            return age;
        }

        @Override
        public String toString() {
            return "Sutdent{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }
}
